<?php

namespace Muyuxuanpay\threePay\src\cj;

use Muyuxuanpay\threePay\BaseTrait;

class Manager
{
    use BaseTrait;
    /**
     * 收银台支付
     * @param array $config
     * @return mixed
     * @throws \Exception
     */
    public function cashRegister(array $config=[])
    {
        $className = __NAMESPACE__ . '\\cashRegister\\Pay';
        if(!class_exists($className)){
            throw new \Exception('支付类型错误');
        }
        return new $className($config);
    }

    /**
     * 协议支付
     * @param array $config
     * @return mixed
     * @throws \Exception
     */
    public function protocolPayment(array $config=[])
    {
        $className = __NAMESPACE__ . '\\protocolPayment\\Pay';
        if(!class_exists($className)){
            throw new \Exception('支付类型错误');
        }
        if(empty($config)){
            $config = $this->config;
        }
        return new $className($config);
    }

    /**
     * js支付
     * @param array $config
     * @return mixed
     * @throws \Exception
     */
    public function jsPayment(array $config=[])
    {
        $className = __NAMESPACE__ . '\\jsPayment\\Pay';
        if(!class_exists($className)){
            throw new \Exception('支付类型错误');
        }
        if(empty($config)){
            $config = $this->config;
        }
        return new $className($config);
    }

    /**
     * 协议支付回调
     * @param array $data
     * @return mixed
     * @throws \Exception
     */
    public function protocolPaymentNotify(array $data)
    {
        $className = __NAMESPACE__ . '\\protocolPayment\\Notify';
        if(!class_exists($className)){
            throw new \Exception('支付类型错误');
        }
        return new $className($data);
    }
}